<%-- 
    Document   : AddConsultant
    Created on : Feb 27, 2014, 11:03:27 AM
    Author     : Mukesh
--%>

<%
    try {
        if (session.getAttribute("uid") != null) {
            if (session.getAttribute("Salary_Fixation").toString().equals("1")) {
%>
<%String to = "", status = "", msg = "";%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Ramgovind Automated System</title>
        <link rel="stylesheet" href="/RIT/css/bootstrap.css">
        <link rel="stylesheet" href="/RIT/css/bootstrap-responsive.css">
        <link rel="stylesheet" href="/RIT/css/jquery.fancybox.css">
        <link rel="stylesheet" href="/RIT/css/style.css">
        <link rel="stylesheet" href="/RIT/css/iconfont.css">
        <link rel="stylesheet" href="/RIT/css/bootstrap.datepicker.css">
        <script src="../../ajax/ajax.js"></script>
        <script type="text/javascript">
        function loadEmployeeSalary()
        {
            document.getElementById('ILoader').setAttribute("style", "visibility: visible;width: 250px;height: 250px;position: absolute;top: 50%;left:50%;margin-top: -80px;margin-left: -40px;background:url(/RIT/img/loader.gif) no-repeat;z-index: 667999;background-size:200px 200px;");
            var empid=document.getElementById('empid').value;
            var xmlhttp;
            if (window.XMLHttpRequest)
            {
                xmlhttp = new XMLHttpRequest();
            }
            else
            {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
                    document.getElementById('3').innerHTML = xmlhttp.responseText;
                    document.getElementById('ILoader').removeAttribute("style");
                }
            }
            xmlhttp.open("POST", "/RIT/EmployeeSalary?empid="+empid, true);
            xmlhttp.send();
        }
        function enableSalary(id, check)
        {
            var table = document.getElementById('tsal');
            var val = document.getElementById('noc').value.split("-");
            var temp = id.split("-");
            if (temp[0] == "1" && check)
            {
                document.getElementById('1-2').readOnly = false;
                document.getElementById('1-2').value ="0";
            }
            else if (temp[0] != "1" && check)
            {
                if (document.getElementById('1-c-2').checked && document.getElementById('1-2').value > 0)
                {
                    document.getElementById(temp[0] + '-' + temp[2]).readOnly = false;
                    document.getElementById(temp[0] + '-' + temp[2]).value ="0";
                }
                else
                {
                    document.getElementById(id).checked = false;
                }
            }
            else if (temp[0] != "1" && !check)
            {
                if (document.getElementById(temp[0] + '-' + temp[2]).value != "")
                {
                    var v = document.getElementById(temp[0] + '-' + temp[2]).value;
                    manageSalOn(temp[0] + '-' + temp[2],document.getElementById(temp[0] + '-' + temp[2]).title, v);
                    document.getElementById(temp[0] + '-' + temp[2]).readOnly = true;
                    document.getElementById(temp[0] + '-' + temp[2]).value = "";
                    document.getElementById(temp[0] + '-' + temp[2]).className ="";
                }
            }
            else
            {
                table.rows[0].cells[1].innerHTML = "0";
                table.rows[1].cells[1].innerHTML = "0";
                table.rows[2].cells[1].innerHTML = "0";
                document.getElementById('1-2').readOnly = true;
                document.getElementById('1-2').value = "";
                for (var i = 0; i < val.length - 1; i++)
                {
                    var k = val[i + 1];
                    var type = k.split("/");
                    document.getElementById(type[0] + '-c-' + type[1]).checked = false;
                    document.getElementById(type[0] + '-' + type[1]).readOnly = true;
                    document.getElementById(type[0] + '-' + type[1]).value = "";
                }
            }
        }
        function manageSal(id, title, val)
        {
            var table = document.getElementById('tsal');
            var ids = id.split("-");
            if (id == "1-2" && document.getElementById('1-2').value == "")
            {
                var table = document.getElementById('tsal');
                table.rows[0].cells[1].innerHTML = "0";
                table.rows[1].cells[1].innerHTML = "0";
                table.rows[2].cells[1].innerHTML = "0";
                var val = document.getElementById('noc').value.split("-");
                for (var i = 0; i < val.length - 1; i++)
                {
                    var k = val[i + 1];
                    var type = k.split("/");
                    document.getElementById(type[0] + '-c-' + type[1]).checked = false;
                    document.getElementById(type[0] + '-' + type[1]).readOnly = true;
                    document.getElementById(type[0] + '-' + type[1]).value = "";
                }
            }
            else
            {
                if (val != "")
                {
                    if (isNaN(document.getElementById(id).value))
                    {
                        document.getElementById(id).value = "";
                    }
                    else
                    {
                        if (title == "earning")
                        {
                            if (ids[1] == "2")
                            {
                                var qty = parseInt(table.rows[0].cells[1].innerHTML) + parseInt(val);
                                table.rows[0].cells[1].innerHTML = qty;
                                table.rows[2].cells[1].innerHTML = parseFloat(table.rows[0].cells[1].innerHTML) + parseFloat(table.rows[1].cells[1].innerHTML);
                                document.getElementById('tote').value = table.rows[0].cells[1].innerHTML;
                                document.getElementById('tota').value = table.rows[2].cells[1].innerHTML;
                            }
                            else
                            {
                                var pval = (parseInt(document.getElementById('1-2').value) * parseInt(val) / 100);
                                table.rows[0].cells[1].innerHTML = parseInt(table.rows[0].cells[1].innerHTML) + parseFloat(pval);
                                table.rows[2].cells[1].innerHTML = parseFloat(table.rows[0].cells[1].innerHTML) + parseFloat(table.rows[1].cells[1].innerHTML);
                                document.getElementById('tote').value = table.rows[0].cells[1].innerHTML;
                                document.getElementById('tota').value = table.rows[2].cells[1].innerHTML;
                            }
                        }
                        else
                        {
                            if (ids[1] == "2")
                            {
                                var qty = parseInt(table.rows[1].cells[1].innerHTML) - parseInt(val);
                                table.rows[1].cells[1].innerHTML = qty;
                                table.rows[2].cells[1].innerHTML = (parseFloat(table.rows[0].cells[1].innerHTML)) + (parseFloat(table.rows[1].cells[1].innerHTML));
                                document.getElementById('totd').value = table.rows[1].cells[1].innerHTML;
                                document.getElementById('tota').value = table.rows[2].cells[1].innerHTML;
                            }
                            else
                            {
                                var pval = (parseInt(document.getElementById('1-2').value) * parseInt(val) / 100);
                                table.rows[1].cells[1].innerHTML = parseInt(table.rows[1].cells[1].innerHTML) - parseFloat(pval);
                                table.rows[2].cells[1].innerHTML = (parseFloat(table.rows[0].cells[1].innerHTML)) + (parseFloat(table.rows[1].cells[1].innerHTML));
                                document.getElementById('totd').value = table.rows[1].cells[1].innerHTML;
                                document.getElementById('tota').value = table.rows[2].cells[1].innerHTML;
                            }
                        }
                    }
                }
            }
        }
        function manageSalOn(id, title, val)
        {
            var table = document.getElementById('tsal');
            var ids = id.split("-");
            if (id == "1-2" && document.getElementById('1-2').value == "")
            {
                var table = document.getElementById('tsal');
                table.rows[0].cells[1].innerHTML = "0";
                table.rows[1].cells[1].innerHTML = "0";
                table.rows[2].cells[1].innerHTML = "0";
                var val = document.getElementById('noc').value.split("-");
                for (var i = 0; i < val.length - 1; i++)
                {
                    var k = val[i + 1];
                    var type = k.split("/");
                    document.getElementById(type[0] + '-c-' + type[1]).checked = false;
                    document.getElementById(type[0] + '-' + type[1]).readOnly = true;
                    document.getElementById(type[0] + '-' + type[1]).value = "";
                }
            }
            else
            {
                if (val != "")
                {
                    if (isNaN(document.getElementById(id).value))
                    {
                        document.getElementById(id).value = "";
                    }
                    else
                    {
                        if (title == "earning")
                        {
                            if (ids[1] == "2")
                            {
                                var qty = parseInt(table.rows[0].cells[1].innerHTML) - parseInt(val);
                                table.rows[0].cells[1].innerHTML = qty;
                                table.rows[2].cells[1].innerHTML = parseFloat(table.rows[0].cells[1].innerHTML) + parseFloat(table.rows[1].cells[1].innerHTML);
                                document.getElementById('tote').value = table.rows[0].cells[1].innerHTML;
                                document.getElementById('tota').value = table.rows[2].cells[1].innerHTML;
                            }
                            else
                            {
                                var pval = (parseInt(document.getElementById('1-2').value) * parseInt(val) / 100);
                                table.rows[0].cells[1].innerHTML = parseInt(table.rows[0].cells[1].innerHTML) - parseFloat(pval);
                                table.rows[2].cells[1].innerHTML = parseFloat(table.rows[0].cells[1].innerHTML) + parseFloat(table.rows[1].cells[1].innerHTML);
                                document.getElementById('tote').value = table.rows[0].cells[1].innerHTML;
                                document.getElementById('tota').value = table.rows[2].cells[1].innerHTML;
                            }
                        }
                        else
                        {
                            if (ids[1] == "2")
                            {
                                var qty = parseInt(table.rows[1].cells[1].innerHTML) + parseInt(val);
                                table.rows[1].cells[1].innerHTML = qty;
                                table.rows[2].cells[1].innerHTML = (parseFloat(table.rows[0].cells[1].innerHTML)) + (parseFloat(table.rows[1].cells[1].innerHTML));
                                document.getElementById('totd').value = table.rows[1].cells[1].innerHTML;
                                document.getElementById('tota').value = table.rows[2].cells[1].innerHTML;
                            }
                            else
                            {
                                var pval = (parseInt(document.getElementById('1-2').value) * parseInt(val) / 100);
                                table.rows[1].cells[1].innerHTML = parseInt(table.rows[1].cells[1].innerHTML) + parseFloat(pval);
                                table.rows[2].cells[1].innerHTML = (parseFloat(table.rows[0].cells[1].innerHTML)) + (parseFloat(table.rows[1].cells[1].innerHTML));
                                document.getElementById('totd').value = table.rows[1].cells[1].innerHTML;
                                document.getElementById('tota').value = table.rows[2].cells[1].innerHTML;
                            }
                        }
                    }
                }
            }
        }
    </script>
    </head>
<body onload="loadEmployeeSalary()">
    <div id="ILoader"></div>
        <%@include file="/topheader.html" %>
        <%@include file="/servicesheader.html" %>
        <div class="main">
            <div class="container-fluid">
                <%@include file="/Services/Payroll/payrollsidenav.html" %>
                <div class="content">
                    <%if (session.getAttribute("status") != null) {
                            status = session.getAttribute("status").toString();
                            msg = session.getAttribute("msg").toString();
                    %>
                    <div class="alert alert-info alert-block">
                        <a class="close" data-dismiss="alert" href="#"><img src="/RIT/img/mclose.png"></a>
                        <h4 class="alert-heading"> <%=status%></h4>
                        <%=msg%>

                    </div>
                    <%session.removeAttribute("status");
                            session.removeAttribute("msg");
                        }%>
                    <div class="row-fluid">
                        <div class="span12">
                            <div class="box">
                                <div class="box-head">
                                    <h3>Salary Fixation</h3>
                                    <div style="float:right;display:flex">
                                    
                                        <b>Emp Name: </b> <%=request.getParameter("emp")%>  &nbsp;|&nbsp; <b>Designation:</b> <%=request.getParameter("desig")%>
                                    
                                </div>
                                </div>
                                <form action="/RIT/AddEmployeeSalDetails" method="post" class='validate form-horizontal'>
                                    <input type="hidden" name="empid" id="empid" value="<%=request.getParameter("empid")%>">
                                    <div class="box-content" id="3">
                                      
                                    </div>
                                    
                                </form>
                            </div>
                        </div>
                    </div>
                </div>	
            </div>
        </div>
        <script src="/RIT/js/jquery.js"></script>
        <script src="/RIT/js/less.js"></script>
        <script src="/RIT/js/bootstrap.min.js"></script>
        <script src="/RIT/js/jquery.uniform.min.js"></script>
        <script src="/RIT/js/bootstrap.timepicker.js"></script>
        <script src="/RIT/js/bootstrap.datepicker.js"></script>
        <script src="/RIT/js/chosen.jquery.min.js"></script>
        <script src="/RIT/js/jquery.fancybox.js"></script>
        <script src="/RIT/js/plupload/plupload.full.js"></script>
        <script src="/RIT/js/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
        <script src="/RIT/js/jquery.cleditor.min.js"></script>
        <script src="/RIT/js/jquery.inputmask.min.js"></script>
        <script src="/RIT/js/jquery.tagsinput.min.js"></script>
        <script src="/RIT/js/jquery.mousewheel.js"></script>
        <script src="/RIT/js/jquery.textareaCounter.plugin.js"></script>
        <script src="/RIT/js/ui.spinner.js"></script>
        <script src="/RIT/js/jquery.jgrowl_minimized.js"></script>
        <script src="/RIT/js/jquery.form.js"></script>
        <script src="/RIT/js/jquery.validate.min.js"></script>
        <script src="/RIT/js/bbq.js"></script>
        <script src="/RIT/js/jquery-ui-1.8.22.custom.min.js"></script>
        <script src="/RIT/js/jquery.form.wizard-min.js"></script>
        <script src="/RIT/js/jquery.cookie.js"></script>
        <script src="/RIT/js/jquery.metadata.js"></script>
        <script src="/RIT/js/custom.js"></script><script src="/RIT/js/demo.js"></script>
        <script src="/RIT/js/iconfont.js"></script>
    </body>
</html>

<%} else {
%>
<script type="text/javascript">
    alert("You Are Not Authorised");
    window.history.back();
</script>
<%             }
        } else {
            request.setAttribute("msg", "You Are Not Authorised! Please Contact to System Administrator!");
            request.setAttribute("value", "0");
            getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
        }
    } catch (Exception e) {
        request.setAttribute("msg", "Please Contact to System Administrator!");
        request.setAttribute("value", "0");
        getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
    }
%>

